﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

using MaxStudio.Concrete.DBUtility;

namespace MaxStudio.Concrete.Server.Dao
{
    public partial class ConcreteDaoDataContext : System.Data.Linq.DataContext
    {
        #region RPTMixingProportionOfConcreteOrder

        public List<tb_RPT_MixingProportionOfConcreteOrder> GetAllMixingProportionOfConcreteOrder()
        {
            var query = (from obj in this.tb_RPT_MixingProportionOfConcreteOrders
                         where obj.IsDelete == 0
                         select obj).ToList();
            return query;
        }


        public List<tb_RPT_MixingProportionOfConcreteOrder> GetMixingProportionOfConcreteOrderByContition(string strInputDate, string strProjectName, string strConstructionUnit
                                                                                                        , string strStrengthGrade, string strApproval
                                                                                                        , string strPlan)
        {
            var tq = from obj in this.tb_RPT_MixingProportionOfConcreteOrders
                     where obj.IsDelete == 0
                     select obj;

            if (strInputDate.Length > 0)
            {
                tq = tq.Where(entity => entity.InputDate == strInputDate);
            }

            if (strProjectName.Length > 0)
            {
                tq = tq.Where(entity => entity.ProjectName == strProjectName);
            }
            if (strConstructionUnit.Length > 0)
            {
                tq = tq.Where(entity => entity.ConstructionUnit == strConstructionUnit);
            }
            if (strStrengthGrade.Length > 0)
            {
                tq = tq.Where(entity => entity.StrengthGrade == strStrengthGrade);
            }

            if (strApproval.Length > 0)
            {
                tq = tq.Where(entity => entity.Approval == strApproval);
            }


            if (strPlan.Length > 0)
            {
                tq = tq.Where(entity => entity.Plan == strPlan);
            }

            var query = tq.ToList();
            return query;
        }

        public tb_RPT_MixingProportionOfConcreteOrder GetMixingProportionOfConcreteOrderById(int id)
        {
            return this.tb_RPT_MixingProportionOfConcreteOrders.SingleOrDefault(tb_RPT_MixingProportionOfConcreteOrders => tb_RPT_MixingProportionOfConcreteOrders.Id == id);
        }

        public void CreateMixingProportionOfConcreteOrder(tb_RPT_MixingProportionOfConcreteOrder entity)
        {
            entity.CreateDate = DateTime.Now;
            entity.CreateBy = 1;
            entity.ModifyDate = DateTime.Now;
            entity.ModifyBy = 1;
            tb_RPT_MixingProportionOfConcreteOrders.InsertOnSubmit(entity);
            this.SubmitChanges();

        }

        public void ModifyMixingProportionOfConcreteOrder(tb_RPT_MixingProportionOfConcreteOrder entity)
        {
            tb_RPT_MixingProportionOfConcreteOrder instance = this.tb_RPT_MixingProportionOfConcreteOrders.SingleOrDefault(p => p.Id == entity.Id);
            instance.InputDate = entity.InputDate;
            instance.ProjectName = entity.ProjectName;
            instance.ConstructionUnit = entity.ConstructionUnit;
            instance.EngineeringSite = entity.EngineeringSite;
            instance.StrengthGrade = entity.StrengthGrade;
            instance.Slump = entity.Slump;
            instance._5Stones = entity._5Stones;
            instance._31Stones = entity._31Stones;
            instance._1Cement = entity._1Cement;
            instance._3Cement = entity._3Cement;
            instance.Fine = entity.Fine;
            instance.CoarseSand = entity.CoarseSand;
            instance.ASH = entity.ASH;
            instance._1Admixture = entity._1Admixture;
            instance._2Admixture = entity._2Admixture;
            instance.Water = entity.Water;
            instance.Remark = entity.Remark;
            instance.Approval = entity.Approval;
            instance.Plan = entity.Plan;  
            

            instance.IsDelete = entity.IsDelete;
            instance.ModifyBy = 1; //Need to get current user
            instance.ModifyDate = DateTime.Now;

            this.SubmitChanges();
        }

        public void DeleteMixingProportionOfConcreteOrder(tb_RPT_MixingProportionOfConcreteOrder entity)
        {
            tb_RPT_MixingProportionOfConcreteOrder deleteEntity = tb_RPT_MixingProportionOfConcreteOrders.SingleOrDefault(p => p.Id == entity.Id);
            tb_RPT_MixingProportionOfConcreteOrders.DeleteOnSubmit(deleteEntity);

            this.SubmitChanges();
        }

        #endregion

    }
}
